From 8dcb5cb96819547e574d4ca619c54c6f902b8860 Mon Sep 17 00:00:00 2001 From: Factiven Date: Thu, 25 May 2023 22:56:21 +0700 Subject: Update v3.6.1 > Added Thumbnail to info page > Temporarily removed Manga from website until the page is finished --- pages/manga/chapter/[chapter].js | 460 --------------------------------------- 1 file changed, 460 deletions(-) delete mode 100644 pages/manga/chapter/[chapter].js (limited to 'pages/manga/chapter/[chapter].js') diff --git a/pages/manga/chapter/[chapter].js b/pages/manga/chapter/[chapter].js deleted file mode 100644 index 14f04ca..0000000 --- a/pages/manga/chapter/[chapter].js +++ /dev/null @@ -1,460 +0,0 @@ -import axios from "axios"; -import Head from "next/head"; -import { useEffect, useState } from "react"; -import Navbar from "../../../components/navbar"; -import Footer from "../../../components/footer"; -import ScrollTracker from "../../../components/scrollTracker"; - -export default function Test({ title, id, aniId, data, provider }) { - const [isLoading, setIsLoading] = useState(true); - const [datas, setData] = useState(data); - const [currentChapter, setCurrentChapter] = useState(null); - const [nextChapter, setNextChapter] = useState(null); - const [prevChapter, setPrevChapter] = useState(null); - - useEffect(() => { - function storedData() { - const nowChap = localStorage.getItem("currentChapterId"); - const chapt = localStorage.getItem("chapters"); - const chapters = JSON.parse(chapt); - const currentChapter = chapters.find((chapter) => chapter.id === nowChap); - const currentIndex = chapters.findIndex( - (chapter) => chapter.id === nowChap - ); - - const nextIndex = currentIndex + 1; - - const nextChapter = chapters[nextIndex]; - const prevIndex = currentIndex - 1; - - setNextChapter(nextChapter); - setCurrentChapter(currentChapter); - setPrevChapter(chapters[prevIndex]); - setIsLoading(false); - } - storedData(); - }, []); - - function getNextChapter() { - window.scrollTo(0, 0); - setIsLoading(true); - const currentId = localStorage.getItem("currentChapterId"); - const scrollData = JSON.parse(localStorage.getItem("watchedManga")) || []; - const scroll = localStorage.getItem("scrollPercentage"); - if (scroll >= 5) { - const existingDataIndex = scrollData.findIndex( - (data) => data.id === currentId - ); - if (existingDataIndex !== -1) { - // Update existing data - scrollData[existingDataIndex].timestamp = Date.now(); - scrollData[existingDataIndex].percentage = parseFloat( - localStorage.getItem("scrollPercentage") - ); - } else { - // Add new data - scrollData.push({ - timestamp: Date.now(), - percentage: parseFloat(localStorage.getItem("scrollPercentage")), - id: currentId, - }); - } - - localStorage.setItem("watchedManga", JSON.stringify(scrollData)); - - const chapt = localStorage.getItem("chapters"); - const chapters = JSON.parse(chapt); - - const currentIndex = chapters.findIndex( - (chapter) => chapter.id === currentId - ); - - const nextIndex = currentIndex + 1; - - const nextChapter = chapters[nextIndex]; - const nexttChapter = chapters[nextIndex + 1]; - const prevChapter = chapters[nextIndex - 1]; - - setNextChapter(nexttChapter); - setCurrentChapter(nextChapter); - setPrevChapter(prevChapter); - - if (!nextChapter) { - return; - } - - fetch( - `https://api.moopa.my.id/meta/anilist-manga/read?chapterId=${nextChapter.id}&provider=${provider}` - ) - .then((response) => response.json()) - .then((data) => { - if (provider === "mangakakalot") { - const datas = data.map((item) => ({ - img: `https://api.consumet.org/utils/image-proxy?url=${item.img}&referer={Referer:'https://mangakakalot.com/'}`, - page: item.page, - title: item.title, - })); - // console.log(datas); - setData(datas); - } else { - const dat = data.map((item) => ({ - img: `https://api.consumet.org/utils/image-proxy?url=${encodeURIComponent( - item.img - )}&referer=${encodeURIComponent(item.headerForImage.Referer)}`, - page: item.page, - title: item.title || null, - })); - setData(dat); - } - }) - .finally(() => { - setIsLoading(false); - }); - - // Update the current chapter id in local storage - localStorage.setItem("currentChapterId", nextChapter.id); - } - - const chapt = localStorage.getItem("chapters"); - const chapters = JSON.parse(chapt); - - const currentIndex = chapters.findIndex( - (chapter) => chapter.id === currentId - ); - - const nextIndex = currentIndex + 1; - - const nextChapter = chapters[nextIndex]; - const nexttChapter = chapters[nextIndex + 1]; - const prevChapter = chapters[nextIndex - 1]; - - setNextChapter(nexttChapter); - setCurrentChapter(nextChapter); - setPrevChapter(prevChapter); - - if (!nextChapter) { - return; - } - - fetch( - `https://api.moopa.my.id/meta/anilist-manga/read?chapterId=${nextChapter.id}&provider=${provider}` - ) - .then((response) => response.json()) - .then((data) => { - if (provider === "mangakakalot") { - const datas = data.map((item) => ({ - img: `https://api.consumet.org/utils/image-proxy?url=${item.img}&referer={Referer:'https://mangakakalot.com/'}`, - page: item.page, - title: item.title, - })); - // console.log(datas); - setData(datas); - } else { - const dat = data.map((item) => ({ - img: `https://api.consumet.org/utils/image-proxy?url=${encodeURIComponent( - item.img - )}&referer=${encodeURIComponent(item.headerForImage.Referer)}`, - page: item.page, - title: item.title || null, - })); - setData(dat); - } - }) - .finally(() => { - setIsLoading(false); - }); - - // Update the current chapter id in local storage - localStorage.setItem("currentChapterId", nextChapter.id); - } - // console.log(data); - - function getPrevChapter() { - // Get the current id - window.scrollTo(0, 0); - setIsLoading(true); - - const currentId = localStorage.getItem("currentChapterId"); - const scrollData = JSON.parse(localStorage.getItem("watchedManga")) || []; - const scroll = localStorage.getItem("scrollPercentage"); - if (scroll >= 5) { - const existingDataIndex = scrollData.findIndex( - (data) => data.id === currentId - ); - if (existingDataIndex !== -1) { - // Update existing data - scrollData[existingDataIndex].timestamp = Date.now(); - scrollData[existingDataIndex].percentage = parseFloat( - localStorage.getItem("scrollPercentage") - ); - } else { - // Add new data - scrollData.push({ - timestamp: Date.now(), - percentage: parseFloat(localStorage.getItem("scrollPercentage")), - id: currentId, - }); - } - - localStorage.setItem("watchedManga", JSON.stringify(scrollData)); - - const chapt = localStorage.getItem("chapters"); - const chapters = JSON.parse(chapt); - - const currentIndex = chapters.findIndex( - (chapter) => chapter.id === currentId - ); - - const nextIndex = currentIndex + 1; - - const nextChapter = chapters[nextIndex]; - const nexttChapter = chapters[nextIndex + 1]; - const prevChapter = chapters[nextIndex - 1]; - - setNextChapter(nexttChapter); - setCurrentChapter(nextChapter); - setPrevChapter(prevChapter); - - if (!nextChapter) { - return; - } - - fetch( - `https://api.moopa.my.id/meta/anilist-manga/read?chapterId=${nextChapter.id}&provider=${provider}` - ) - .then((response) => response.json()) - .then((data) => { - if (provider === "mangakakalot") { - const datas = data.map((item) => ({ - img: `https://api.consumet.org/utils/image-proxy?url=${item.img}&referer={Referer:'https://mangakakalot.com/'}`, - page: item.page, - title: item.title, - })); - // console.log(datas); - setData(datas); - } else { - const dat = data.map((item) => ({ - img: `https://api.consumet.org/utils/image-proxy?url=${encodeURIComponent( - item.img - )}&referer=${encodeURIComponent(item.headerForImage.Referer)}`, - page: item.page, - title: item.title || null, - })); - setData(dat); - } - }) - .finally(() => { - setIsLoading(false); - }); - - // Update the current chapter id in local storage - localStorage.setItem("currentChapterId", nextChapter.id); - } - - const chapt = localStorage.getItem("chapters"); - const chapters = JSON.parse(chapt); - - const currentIndex = chapters.findIndex( - (chapter) => chapter.id === currentId - ); - - const prevIndex = currentIndex - 1; - - const prevChapter = chapters[prevIndex]; - const nextChapter = chapters[prevIndex + 1]; - const prevvChapter = chapters[prevIndex - 1]; - setCurrentChapter(prevChapter); - setNextChapter(nextChapter); - setPrevChapter(prevvChapter); - - fetch( - `https://api.moopa.my.id/meta/anilist-manga/read?chapterId=${prevChapter.id}&provider=${provider}` - ) - .then((response) => response.json()) - .then((data) => { - // console.log(data); - if (provider === "mangakakalot") { - const datas = data.map((item) => ({ - img: `https://api.consumet.org/utils/image-proxy?url=${item.img}&referer={Referer:'https://mangakakalot.com/'}`, - page: item.page, - title: item.title, - })); - // console.log(datas); - setData(datas); - } else { - const dat = data.map((item) => ({ - img: `https://api.consumet.org/utils/image-proxy?url=${encodeURIComponent( - item.img - )}&referer=${encodeURIComponent(item.headerForImage.Referer)}`, - page: item.page, - title: item.title || null, - })); - setData(dat); - } - }) - .finally(() => { - setIsLoading(false); - }); - - // Update the current chapter id in local storage - localStorage.setItem("currentChapterId", prevChapter.id); - } - // console.log({ PREV_CHAPTER: prevChapter }); - // console.log({ CURRENT_CHAPTER: currentChapter }); - // console.log({ NEXT_CHAPTER: nextChapter }); - - return ( - <> - - {title} - - - - - - - -
-
- {isLoading ? ( -
- ) : currentChapter && currentChapter.chapter ? ( -

Chapter {currentChapter.chapter}

- ) : ( -

{currentChapter.title}

- )} -
- - {isLoading ? ( -

Loading...

- ) : ( -
- {datas.length > 0 && - datas.map((item, index) => ( - {`Page - ))} -
- )} - {isLoading ? ( -
- ) : ( - <> -
-
- - - -
-
- - - -
-
- -
- {nextChapter ? ( - nextChapter.chapter ? ( -

Next Chapter {nextChapter.chapter}

- ) : ( -

Next Chapter {nextChapter.title}

- ) - ) : ( -

End of Chapter

- )} -
- - )} -
-